<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ page import="board1.BoardDAO"%>
<%@ page import="board1.BoardTO"%>
<%@ page import="board1.UserDAO"%>
<%@ page import="board1.UserTO"%>
<%@ page import="java.util.ArrayList"%>

<%
	request.setCharacterEncoding("UTF-8");

	BoardDAO dao = new BoardDAO();

 	ArrayList<BoardTO> data = dao.listBoard(request.getParameter("board_id"),request.getParameter("chon_id"));
 	
 	String board_list ="";
 	
 	
 	
 	
	UserDAO user_dao = new UserDAO();
	UserTO user_to = new UserTO();

 	
 	
 	for (int i = 0; i < data.size(); i++) {
 		BoardTO to = (BoardTO) data.get(i);
 		String idx = to.getIdx();
 		String chon_id = to.getChon_id();
 		String board_id = to.getBoard_id();
 		String phone_number = to.getPhone_number();
 		String title = to.getTitle();
  		String content = to.getContent();
  		String view_lv = to.getView_lv();
  		String cnt = to.getHit();
  		String wr_dt = to.getWr_dt();
  		String from_dt = to.getFrom_dt();
  		String end_dt = to.getEnd_dt();
  		String pic_names = to.getPic_name();
  		
  		//String user_name ="test_name";

  		user_to.setPhone_number(phone_number);
  		user_to = (UserTO) user_dao.viewUser(user_to);
 		
		if (i == 0) {
			board_list = "{" 
					+ "\"idx\":\"" + idx  + "\","
					+ "\"chon_id\":\"" + chon_id + "\"," 					
					+ "\"phone_number\":\"" + phone_number + "\"," 
					+ "\"user_name\":\"" + user_to.getUser_name() + "\"," 					
					+ "\"title\":\"" + title + "\","
					+ "\"content\":\"" + content + "\","
					+ "\"view_lv\":\"" + view_lv + "\","
					+ "\"cnt\":\"" + cnt + "\","					
					+ "\"wr_dt\":\"" + wr_dt + "\","	
					+ "\"from_dt\":\"" + from_dt + "\","
					+ "\"end_dt\":\"" + from_dt + "\","							
					+ "\"pic_names\":\"" + pic_names
					+ "\"}";
		} else {
			board_list += ",{" 
					+ "\"idx\":\"" + idx  + "\","
					+ "\"chon_id\":\"" + chon_id + "\"," 					
					+ "\"phone_number\":\"" + phone_number + "\"," 
					+ "\"user_name\":\"" + user_to.getUser_name() + "\"," 					
					+ "\"title\":\"" + title + "\","
					+ "\"content\":\"" + content + "\","
					+ "\"view_lv\":\"" + view_lv + "\","
					+ "\"cnt\":\"" + cnt + "\","					
					+ "\"wr_dt\":\"" + wr_dt + "\","	
					+ "\"from_dt\":\"" + from_dt + "\","
					+ "\"end_dt\":\"" + from_dt + "\","							
					+ "\"pic_names\":\"" + pic_names
					+ "\"}";
		}
  		
 	}
 	
	if (board_list.equals(""))
		board_list = "FAIL";
	else
		board_list = "[" + board_list + "]";	
	
	out.println(board_list);
 %>
